﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ChineseSchool.BLL;
using ChineseSchool.Models.Hethong;

namespace ChineseSchool.UserControl.ThuNghiem
{
    public partial class Lessons : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack) return;
            lblLessons.Text = LoadLessons();
        }

        public string LoadLessons()
        {
            var str = "";
            var lstTopLessons = new B_Lessons().GetLastestLesson();
            if (lstTopLessons != null && lstTopLessons.Count > 0)
            {
                foreach (var lessons in lstTopLessons)
                {                    
                    str += "<article>";
                    str += "    <figure class=\"blog-thumbnails\">";
                    str += "        <img src=\"" + lessons.ImageUrl + "\" alt=\"" + lessons.LessonTitle + "\">";
                    str += "    </figure>     ";
                    str += "    <div class=\"blog-text\">";
                    str += "        <h1><a href=\"" + Util.MakeLinkLessonDetail(lessons.LessonID.ToString(CultureInfo.InvariantCulture), Encode.Uni2KD(lessons.LessonTitle)) + "\">" + lessons.LessonTitle + " </a></h1>";
                    str += "        <p>";
                    str += "            " + lessons.LessonSummary + "";
                    str += "        </p>";
                    str += "        <div class=\"meta-data\">";
                    str += "            <a href=\"#\" class=\"like\"><i class=\"fa fa-thumbs-o-up\"></i>08</a>";
                    str += "            <a href=\"#\" class=\"comments\"><i class=\"fa fa-comments-o\"></i>49</a>";
                    str += "            <span class=\"read-more\"><a href=\"" + Util.MakeLinkLessonDetail(lessons.LessonID.ToString(CultureInfo.InvariantCulture), Encode.Uni2KD(lessons.LessonTitle)) + "\">Chi tiết</a></span>";
                    str += "        </div>";
                    str += "    </div>";
                    str += "</article>";
                }
            }
            return str;
        }
    }
}